package com.inforich.app.api.controller.area;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.inforich.area.domain.Area;
import com.inforich.area.service.IAreaService;
import com.inforich.common.core.domain.AjaxResult;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 地区
 * @author: HJM
 * @date: 2022/10/31
 */
@RestController
@RequestMapping("/h5api/area")
public class AppAreaController {

  @Autowired
  private IAreaService areaService;

  /**
   * 地区树
   */
  @GetMapping("/tree")
  public AjaxResult selectBuildingTypeTreeList() {
    List<Area> parentList = areaService.list(new LambdaQueryWrapper<Area>()
        .eq(Area::getLevel, "10"));
    List<Area> list1 = areaService.list(new LambdaQueryWrapper<Area>()
        .eq(Area::getLevel, "20"));
    List<Area> list2 = areaService.list(new LambdaQueryWrapper<Area>()
        .eq(Area::getLevel, "30"));
    list2.addAll(list1);
    return AjaxResult.success(areaService.selectAreaTreeList(parentList, list2));
  }

}
